<template>
  <div class="container">
    <div class="count-down-times" v-if="endTime>0">{{ endTime }}</div>
    <div class="currentTime">
      <div class="time">
        <span class="dateTime">{{ date }}</span>
        <span class="secondTime">{{ time }}</span>
      </div>
    </div>
    <el-row>
      <EnterpriseEstablishment />
      <ConstructionProject />
    </el-row>
  </div>
</template>

<script>
import EnterpriseEstablishment from "./components/enterprise-establishment.vue"; // 企业设立
import ConstructionProject from "./components/construction-project.vue"; // 青岛市建设项目情况分析
import moment from "moment";
// import { countDownTimes } from "@/utils/common";
export default {
  name: "index",
  components: {
    EnterpriseEstablishment,
    ConstructionProject,
  },
  data() {
    return {
      // jumpTime: null
      date: moment().format("YYYY年MM月DD日"),
      time: moment().format("HH:mm:ss"),
      endTime: 0, //倒计时 时间
    };
  },
  activated() {
    let jumpTmFun = this.GLOBAL.getJumpTime();
    jumpTmFun.then((resData) => {
      this.endTime = resData.data;
      if (this.endTime > 0) {
        // 1.5分钟后跳转到index1大屏
        this.countDownTimes();
      }
    });
  },
  created() {
    // 获取Promise对象的值
    // let jumpTmFun = this.GLOBAL.getJumpTime();
    // jumpTmFun.then((resData) => {
    //   if (resData.data > 0) {
    //     // 1.5分钟后跳转到index1大屏
    //     setTimeout(() => {
    //       this.$router.push({ path: "/index1" });
    //     }, 1000 * resData.data);
    //   }
    // });
  },
  mounted() {
    // if (this.jumpTime > 0) {
    //   // 20分钟后跳转到index1大屏
    //   setTimeout(() => {
    //     this.$router.push({ path: '/index1' })
    //   }, this.jumpTime)
    // }
    this.dateTimeChange();
  },
  methods: {
    dateTimeChange() {
      var b = setInterval(() => {
        this.time = moment().format("HH:mm:ss");
        clearInterval(b);
        this.dateTimeChange();
      }, 1000);
    },
    // 倒计时
    countDownTimes() {
      var interval = setInterval(() => {
        this.endTime -= 1;
        if (this.endTime == -1) {
          this.endTime = 0;
          clearInterval(interval);
          //跳转页面
          this.$router.push({ path: "/index1" });
        }
      }, 1000);
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.container {
  width: 4000px;
  height: 1200px;
  background: #050f3b;
  padding: 40px 35px;
  .currentTime {
    width: 4000px;
    position: absolute;
    left: 0;
    right: 0;
    text-align: center;
    .time {
      font-size: 40px;
      font-weight: 700;
      font-family: 微软雅黑;
      .dateTime {
        padding-right: 10px;
      }
      .secondTime {
        padding-left: 15px;
      }
    }
  }
}
</style>